using System;
using System.Collections.Generic;
using System.Web;
using System.Web.Services;
using Web.Core;

namespace AsmxData
{
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    public class PropertyTypeHandler : System.Web.Services.WebService
    {
        /// 
        [WebMethod]
        public string getList(string injson)
        {
		    JsonFormat jsf = new JsonFormat(injson);
		    if (!Authority.CheckAuthOnAsmx("PropertyTypeHandler.getList",jsf.GetValue("authid"), jsf.GetValue("authstr"), true))
			  return "{\"result\":\"-1\"}";
            int pagesize = Int16.Parse(jsf.GetValue("rows"));
            int currentpage = Int16.Parse(jsf.GetValue("page"));
            PageInfo pi = new PageInfo();
            pi.PageSize = pagesize;
            pi.PageIndex = currentpage;
    		Model.PropertyType mdl = new Model.PropertyType();
        
            PageList<Model.PropertyType> lst = new BLL.PropertyType().GetPageList(pi, mdl);
            string json = "{\"total\":" + pi.RecordCount.ToString()+",\"rows";
            json = Newtonsoft.Json.JavaScriptConvert.SerializeObject(lst).Replace("{\"List", json);
			return json;
        }

        /// 
        [WebMethod]
        public string getOne(string injson)
        {
		    JsonFormat jsf = new JsonFormat(injson);
		    if (!Authority.CheckAuthOnAsmx("PropertyTypeHandler.getOne",jsf.GetValue("authid"), jsf.GetValue("authstr"), true))
			  return "{\"result\":\"-1\"}";
            int? id = BLL.BLHelper.GetInt(jsf.GetValue("id"));
	    	Model.PropertyType wheremdl = new Model.PropertyType();
    		wheremdl.PropertyTypeId = id;
            Model.PropertyType mdl = new BLL.PropertyType().GetModel(wheremdl);
            string json = "\"result\":{0},\"model\":{1}";
            if (mdl == null)
                json = String.Format(json, 0, "{}");
            else
                json = String.Format(json, 1, Newtonsoft.Json.JavaScriptConvert.SerializeObject(mdl));
            return "{" + json + "}";
        }

        /// 
        [WebMethod]
        public string AddOne(string injson)
        {
		    JsonFormat jsf = new JsonFormat(injson);
		    if (!Authority.CheckAuthOnAsmx("PropertyTypeHandler.AddOne",jsf.GetValue("authid"), jsf.GetValue("authstr"), true))
			  return "{\"result\":\"-1\"}";
            Model.PropertyType mdl = new Model.PropertyType();
	
            mdl.PropertyTypeName = BLL.BLHelper.GetString(jsf.GetValue("PropertyTypeName"));
            new BLL.PropertyType().Add(mdl);
            return "{\"result\":\"1\"}";
        }

        /// 
        [WebMethod]
        public string RemoveOne(string injson)
        {
		    JsonFormat jsf = new JsonFormat(injson);
		    if (!Authority.CheckAuthOnAsmx("PropertyTypeHandler.RemoveOne",jsf.GetValue("authid"), jsf.GetValue("authstr"), true))
			  return "{\"result\":\"-1\"}";
            int? id = BLL.BLHelper.GetInt(jsf.GetValue("id"));
            Model.PropertyType wheremdl = new Model.PropertyType();
	    	wheremdl.PropertyTypeId = id;
	    	new BLL.PropertyType().Delete(wheremdl);
	    	return "{\"result\":\"1\"}";
        }

        /// 
        [WebMethod]
        public string UpdataOne(string injson)
        {
		    JsonFormat jsf = new JsonFormat(injson);
		    if (!Authority.CheckAuthOnAsmx("PropertyTypeHandler.UpdataOne",jsf.GetValue("authid"), jsf.GetValue("authstr"), true))
			  return "{\"result\":\"-1\"}";
            Model.PropertyType setmdl = new Model.PropertyType();
	    	Model.PropertyType wheremdl = new Model.PropertyType();
	
            setmdl.PropertyTypeId = BLL.BLHelper.GetInt(jsf.GetValue("PropertyTypeId"));
            setmdl.PropertyTypeName = BLL.BLHelper.GetString(jsf.GetValue("PropertyTypeName"));

            new BLL.PropertyType().Update(setmdl, wheremdl);
            return "{\"result\":\"1\"}";
        }
    }
}
  